{extend name='public/window' /}


{block name="content"}
<div class="layui-fluid">
    <div class="layui-card">

        <div class="layui-card-body" style="padding: 15px;">
            <div class="layui-form">

                {:token()}

                {lv:InputForm label="角色名称：" name="name"  place="请输入角色名称" verify="required"  word="角色名称不能为空和重复"  /}

                <div class="layui-form-item">
                    <label class="layui-form-label label-required-next">选择权限：</label>
                    <div class="layui-input-block">
                        <div id="LAY-auth-tree-index"></div>
                    </div>
                </div>


                {:widget('common/forms/submit',array('add','立即提交'))}


            </div>
        </div>
    </div>
</div>


<script>

    layui.use(['element', 'form', 'jquery','upload','authtree','lucky'], function () {
        var element = layui.element;
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var authtree = layui.authtree;
        var lucky=layui.lucky;

        // 初始化
        $.ajax({
            url: "{:url('getRoles')}",
            dataType: 'json',
            type:'post',
            data:{id:""},
            success: function(data){
                // 渲染时传入渲染目标ID，树形结构数据（具体结构看样例，checked表示默认选中），以及input表单的名字
                authtree.render('#LAY-auth-tree-index', data.data, {
                    inputname: 'rule[]'
                    ,layfilter: 'lay-check-auth'
                    ,autowidth: true
                });
            },
            error: function(xml, errstr, err) {
                layer.alert(errstr+'，获取数据失败！');
            }
        });

        /**
         * 提交表单数据
         */
        form.on('submit(add)', function (data) {
            lucky.FormSubmit("{:url('addRole')}",data.field,"table_id",1);
            return false;
        });

    })
</script>

{/block}